<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 3:18
 */
namespace app\blog\controller;
use app\blog\model\BrandModel as br;
use cmf\controller\AdminBaseController;
class BrandController extends AdminBaseController{
    /**
     * 商品品牌
     */
    public function _initialize()
    {
        parent::_initialize();
        $this->br=new br();
    }

    public function index(){
        $param = $this->request->param('name');

        $session=$this->br->session();
        $shopid=$session['id'];
        //商品品牌
        $rest    = $this->br->index($param);
        $rest->appends(['name'=>$param,'shop_id'=>$shopid]);
        $this->assign('users',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('brand/index');
    }
    /**
     * 添加商品品牌
     */
    public function add(){
        return $this->fetch('brand/add');

    }
    /**
     * 添加商品品牌操作
     */
    public function addPost(){
        $date       = $this->request->param();
        $rest       = $this->br->add($date);
        if($rest != false){
            $this->success('操作成功！','brand/index');
        }else{
            $this->error('操作失败！');
        }

    }
    /**
     * 修改商品品牌页面
     */
    public function detail(){
        //获取指定商品品牌
        $array=$this->request->param();
        $where['id']=$array['id'];
        $rest      = $this->br->getGone($where);
        $this->assign('rest',$rest);
        return $this->fetch();
    }
    /**
     * 修改商品品牌操作
     */
    public function detailPost(){
        $date     = $this->request->param();
        $where['id'] = $date['id'];
        $data['name']=$date['name'];
        $rst      = $this->br->goodspecupdate($where,$data);
        if($rst != false){
            $this->success('修改成功！','brand/index');
        }else{
            $this->error('修改失败');
        }
    }
    /**
     * 删除商品品牌
     */
    public function del(){
        $date     = $this->request->param();
        $where['id']       =$date['id'];
        $rst      = $this->br->del($where);
        if($rst['num'] != false){
            $this->success($rst['con']);
        }else{
            $this->error($rst['con']);
        }
    }
    /*禁用启用功能*/
    public function upStatus(){
        $date        = $this->request->param();
        $where       = array();
        $where['id'] = $date['id'];
        $data['status']=$date['status'];
        $rest        = $this->br->goodspecupdate($where,$data);
        if($rest != false){
            $this->success("操作成功！");
        }else{
            $this->error('操作失败');
        }
    }
}